﻿using System;

class HexadecimalToDecimal
{
    static void Main()
    {
        //Exercise 4.
        //Write a program to convert hexadecimal numbers to their decimal representation.

        //For example: FE -> 254; 1F4 -> 500

        Console.Write("Enter a hexadecimal number: ");
        string numberHexa = Console.ReadLine();

        int number = 0;
        int digit = 0;
        int power = 0;
        for (int i = numberHexa.Length - 1; i >= 0; i--)
        {           
            switch (numberHexa[i])
            {
                case 'A':
                    digit = 10;
                    break;
                case 'B':
                    digit = 11;
                    break;
                case 'C':
                    digit = 12;
                    break;
                case 'D':
                    digit = 13;
                    break;
                case 'E':
                    digit = 14;
                    break;
                case 'F':
                    digit = 15;
                    break;
                default:
                    digit = int.Parse(numberHexa[i].ToString());                    
                    break;
            }
            number = number + digit * (int)Math.Pow(16, power);
            power++;
        }
        Console.WriteLine(number);   
    }
}

